﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MpSoft.Library.DAO.Categorys;
using MpSoft.Library.DTO;
using MpSoft.Basic.Configuration;

namespace MpSoft.Library.BUSS.Categories
{
    public class NavigateBUSS
    {
        private const string Navigate_ALL_KEY = "Mp.navigate.all";
        private const string Navigate_ALL_DIC_KEY = "Mp.navigate.all.dic";
        public static void RemoveNavigate()
        {
            MpCache.Remove(Navigate_ALL_KEY);
            MpCache.Remove(Navigate_ALL_DIC_KEY);
        }

        public static List<ENavigate> Navigate_ByParent(string parent, List<ENavigate> listNav)
        {
            List<ENavigate> list = null;
            if (listNav != null)
            {
                list = new List<ENavigate>(1);
                foreach (var obj in listNav)
                    if (obj.Parent.Equals(parent)&&obj.Show.Equals("1"))
                        list.Add(obj);
            }
            return list;
        }

        public static Dictionary<string, ENavigate> Navigate_ByDic()
        {
            object list = MpCache.Get(Navigate_ALL_DIC_KEY);
            if (list != null)
                return (Dictionary<string, ENavigate>)list;
            var list2 = Navigate_List().ToDictionary(item => item.ID) ;
            MpCache.Max(Navigate_ALL_DIC_KEY, list);
            return list2;
        }

        public static List<ENavigate> Navigate_List()
        {
            object list = MpCache.Get(Navigate_ALL_KEY);
            if (list != null)
                return (List<ENavigate>)list;
            var list2 = NavigateDAO.Navigate_List();
            if (list2 != null)
            {
                MpCache.Max(Navigate_ALL_KEY, list2);
                return list2;
            }
            return null;
        }
    }
}
